package com.jojo.jojomall.search.controller;

import com.jojo.common.exception.BizCodeEnum;
import com.jojo.common.to.es.skuEsModel;
import com.jojo.common.utils.R;
import com.jojo.jojomall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/search")
public class ElasticSaveController {
    @Autowired
    ProductSaveService productSaveService;
    /**
     * 上架商品
     * @param skuEsModels  commons下的to的传输工具类
     * @return
     */

    @PostMapping("/product")
public R productStartUp(@RequestBody List<skuEsModel> skuEsModels) {
        Boolean b=false;
        try {
//调用业务层去实现想要实现的功能；
           b = productSaveService.productStartUp(skuEsModels);
        } catch (IOException e) {
        log.error("商品上架发生错误：{}",e);
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }

        return b==true?R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg()): R.ok();
}
}
